package net.sf.marineapi.ais.util;

/**
 * Checks the ship type for validity.
 * 
 * @author Lázár József
 */
public class ShipType {

	final static private String[] SPECIAL = {
			"Pilot vessel",
			"Search and rescue vessel",
			"Tug",
			"Port tender",
			"Vessel with anti-pollution capability",
			"Law enforcement vessel",
			"Spare - for local vessels",
			"Spare - for local vessels",
			"Medical transport",
			"Ship not party to an armed conflict"
	};

	final static private String[] FIRST_DIGIT = {
			"Not specified",
			"Reserved for future use",
			"WIG",
			"Vessel",
			"HSC",
			"See above",
			"Passenger ship",
			"Cargo ship",
			"Tanker",
			"Other types of ship"
	};
	
	final static private String[] SECOND_DIGIT = {
			"General",
			"Category X",
			"Category Y",
			"Category Z",
			"Category OS",
			"Reserved for future use",
			"Reserved for future use",
			"Reserved for future use",
			"Reserved for future use",
			"No additional information"
	};

	final static private String[] VESSEL = {
			"Fishing",
			"Towing",
			"Towing and exceeding",
			"Engaged in dredging or underwater operations",
			"Engaged in diving operations",
			"Engaged in military operations",
			"Sailing",
			"Pleasure craft",
			"Reserved for future use",
			"Reserved for future use"
	};
	
	/**
	 * Return string describing the ship and cargo type.
	 * @return a text string describing the ship and cargo type.
	 */
	static public String shipTypeToString (int type) {
		String typeStr ="N/A";
		if (0 <= type && type <= 255) {
			if (type >= 200)
				return "Reserved for future use";
			if (type >= 100)
				return "Reserved for regional use";
			if (type == 0)
				return "Not available / no ship";

			int d1 = type / 10;
			int d2 = type % 10;
			if (0 <= d1 && d1 <= 9 && 0 <= d2 && d2 <= 9) {
				switch(d1) {
				case 0:
					return FIRST_DIGIT[0] + " " + Integer.toString(type);
				case 3:
					return FIRST_DIGIT[3] + ", " + VESSEL[d2];
				case 5: 
					return SPECIAL[d2];
				default:
					return FIRST_DIGIT[d1] + ", " + SECOND_DIGIT[d2]; 
				}
			}
		}
		return typeStr;
	}
}